﻿// --------------------------------
// <copyright file="ParticleEffectGenerator.cs" company="Faculty of Information Technology, Czech Technical University in Prague">
//     This document is shared by Microsoft Public License (MS-PL)
//     For further details please see http://msdn.microsoft.com/en-us/library/ff648068.aspx or license.txt.
// </copyright>
// <author>Vladislav Richter</author>

// <email>richtvl2@fit.cvut.cz</email>

// <date>9. 11. 2011 22:22:37</date>

// <summary>
//
// </summary>
// --------------------------------
using Microsoft.Xna.Framework;

#if WINDOWS

using System.ComponentModel;
using FITClub.Episode1.Levels;
using System.Drawing.Design;

#endif

using System.Xml.Serialization;
using System.IO;

namespace FITClub.Episode1.Components.Particles.ParticleSystems
{
    /// <summary>
    /// Selects draw order of the generator among other game components
    /// </summary>
    public enum DrawPosition { BeforeFluid, BeforeBackgroundItems, BeforePlatforms, BeforeCharacters, AfterCharacters }

    /// <summary>
    /// This class represents settings for new particle effect system in the game
    /// </summary>
    public class ParticleEffectGenerator
    {
#if WINDOWS

        [Category("Path")]
        [Editor(typeof(ContentPathEditor), typeof(UITypeEditor))]
        [EditorBrowsable(EditorBrowsableState.Always)]
#endif
        public string ParticleSettingsPath { get; set; }

        public Vector3 Position { get; set; }

        public DrawPosition DrawOrder { get; set; }

        public ParticleEffectGenerator()
        {
            this.DrawOrder = DrawPosition.BeforeCharacters;
            this.ParticleSettingsPath = string.Empty;
        }

        public static ParticleSettings DeserializeXML(Stream input)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ParticleSettings));
            return serializer.Deserialize(input) as ParticleSettings;
        }

        public ParticleSettings Deserialize()
        {
            using (Stream input = TitleContainer.OpenStream(ParticleSettingsPath))
            {
                return DeserializeXML(input);
            }
        }

        public override string ToString()
        {
            return string.Format("[{0}; {1}; {2}] {3}", this.Position.X, this.Position.Y, this.Position.Z, this.GetType().Name);
        }
    }
}